package servlet;

import java.io.IOException;
import java.util.List;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import dao.ContentDAO;
import dao.ThemeDAO;
import entity.Content;
import entity.Theme;
import entity.User;

/**
 * Servlet implementation class BeforeAddArticle
 */
@WebServlet("/BeforeAddArticle")
public class BeforeAddArticle extends HttpServlet {
	private static final long serialVersionUID = 1L;
    private ThemeDAO themeDAO = ThemeDAO.getInstance(); 
    /**
     * @see HttpServlet#HttpServlet()
     */
    public BeforeAddArticle() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		request.setCharacterEncoding("utf-8");
		response.setCharacterEncoding("utf-8");
		
		/*User user = new User(1, "111111", "请问长得太帅怎么办", 0,0, "619728921@qq.com","18092815820");
		HttpSession session = request.getSession(true);
		session.setAttribute("user", user);*/
	
		List<Theme> themelist = themeDAO.getAll();
		request.setAttribute("themelist", themelist);
		System.out.println(themelist.toString());
		request.getRequestDispatcher("AddArticle.jsp").forward(request, response);
		//Content content = new Content(9,"1111111");
		//ContentDAO.getInstance().add(content);
		
		//response.getWriter().append("Served at: ").append(request.getContextPath());
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
		doGet(request, response);
	}

}
